package ch.sv7.tool.dbmanager.db.fix;

import ch.sv7.tool.dbmanager.db.IndexSchema;
import ch.sv7.tool.dbmanager.db.SchemaElement;
import ch.sv7.tool.dbmanager.db.dialect.DialectException;

/**
 * TODO: Document me!
 *
 * @author svt
 *
 */
public class RenameIndexFix extends AbstractSchemaFix implements SchemaFix {


	private IndexSchema actualIndexSchema;
	private IndexSchema expectedIndexSchema;

	/**
	 * @param actualIndexSchema
	 * @param expectedIndexSchema
	 */
	public RenameIndexFix(IndexSchema actualIndexSchema, IndexSchema expectedIndexSchema) {
		super();
		this.actualIndexSchema = actualIndexSchema;
		this.expectedIndexSchema = expectedIndexSchema;
	}

	public SchemaElement getActionTarget() {
		return expectedIndexSchema;
	}
	
	public String getSQLFix() throws DialectException {
		String ddl = "\n-- Rename index Fix \n";
		ddl += getDialect().getRenameIndexDDL(actualIndexSchema, expectedIndexSchema.getName());
		return ddl;
	}

	public int getPriority() {
		return SchemaFix.PRIORITY_COLUMN_RENAME;
	}

	public String getDescription() {
		return "Rename index " + actualIndexSchema.getTableSchema().getName() + "." + actualIndexSchema.getName() + " to " + expectedIndexSchema.getName();
	}

	public int getAction() {
		return ACTION_EDIT;
	}

	
}
